var t = require;
var e = module;
var o = exports;
var i, n = this && this.__extends || (i = function(t, e) {
    return (i = Object.setPrototypeOf || {
        __proto__: []
    }
    instanceof Array &&
    function(t, e) {
        t.__proto__ = e
    } ||
    function(t, e) {
        for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o])
    })(t, e)
},
function(t, e) {
    function o() {
        this.constructor = t
    }
    i(t, e),
    t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o)
}),
a = this && this.__decorate ||
function(t, e, o, i) {
    var n, a = arguments.length,
    r = a < 3 ? e: null === i ? i = Object.getOwnPropertyDescriptor(e, o) : i;
    if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, o, i);
    else for (var s = t.length - 1; s >= 0; s--)(n = t[s]) && (r = (a < 3 ? n(r) : a > 3 ? n(e, o, r) : n(e, o)) || r);
    return a > 3 && r && Object.defineProperty(e, o, r),
    r
};
Object.defineProperty(o, "__esModule", {
    value: !0
});
var r, s = t("GlobalUserData"),
l = t("HallConstant"),
c = t("HallScene"),
d = t("Hint"),
h = t("BroadCastMessage"),
p = t("Util"),
u = t("Global"),
f = t("StorageManager"),
m = t("BaseStorage"),
_ = t("BonusUtil"),
y = t("TimeUtil"),
g = t("Award"),
v = t("ReceiveAward"),
C = cc._decorator,
b = C.ccclass,
w = C.property; (function(t) {
    t[t.primary = 0] = "primary",
    t[t.intermediate = 1] = "intermediate",
    t[t.advanced = 2] = "advanced",
    t[t.special = 3] = "special",
    t[t.ss = 4] = "ss"
})(r || (r = {}));
var S = function(t) {
    function e() {
        var e = null !== t && t.apply(this, arguments) || this;
        return e.grade = r.primary,
        e.title = null,
        e.gradeFrame = null,
        e.timestamp = null,
        e.awardPrefab = null,
        e.receiveAwardPrefab = null,
        e.coinPrefab = null,
        e.boxPrefab = null,
        e.coinIcon = null,
        e.giftCountainer = null,
        e.startBtn = null,
        e.strengthNode = null,
        e.coolDownNode = null,
        e.taskProgNode = null,
        e.receiveBtn = null,
        e.videoIcon = null,
        e.coolTimestamp = null,
        e.taskTimeLabel = null,
        e.coolProgress = null,
        e.taskProgress = null,
        e.titleFrames = [],
        e.giftFrames = [],
        e.giftIcons = [],
        e.firstGiftIcons = [],
        e.taskTimes = [1 / 6, .5, 4, 8, 8],
        e.coinCounts = [1e3, 2500, 4500, 1e4, 500],
        e.diamondCounts = [5, 20, 50, 100, 1],
        e.strengthNums = [0, 0, 5, 10, 15],
        e.coolDownTimes = [0, .5 / 6, .5, 4, 8],
        e.firstTags = [u.BonusType.Coin, u.BonusType.Coin, u.BonusType.Coin, u.BonusType.Coin, u.BonusType.Diamond],
        e.tags = [u.BonusType.Diamond, u.BonusType.Diamond, u.BonusType.Diamond, u.BonusType.Diamond, u.BonusType.Box_senior],
        e.btnManagerArr = [],
        e.gifts = [{
            tag: u.BonusType.Coin,
            icon: null,
            value: null,
            prefab: null
        },
        {
            tag: u.BonusType.Coin,
            icon: null,
            value: null,
            prefab: null
        }],
        e.firstPrefab = null,
        e.secdPrefab = null,
        e
    }
    return n(e, t),
    e.prototype.onLoad = function() {
        var t = Number(this.grade);
        this.title.spriteFrame = this.titleFrames[t],
        this.gradeFrame.spriteFrame = this.giftFrames[t],
        this.taskTime = this.taskTimes[t],
        this.timestamp.string = ":" + y.default.parse_timestamp_time_hours(y.default.convert_hours_to_milliseconds(this.taskTime)),
        this.diamondIcon = this.giftIcons[t],
        this.coinIcon = this.firstGiftIcons[t],
        this.coinCount = this.coinCounts[t],
        this.diamondCount = this.diamondCounts[t],
        this.strengthNum = this.strengthNums[t],
        this.coolDownTime = this.coolDownTimes[t],
        this.tag = this.tags[t],
        this.firstTag = this.firstTags[t],
        this.firstPrefab = this.coinPrefab,
        this.secdPrefab = this.tag == u.BonusType.Diamond || this.tag == u.BonusType.Coin ? this.coinPrefab: this.boxPrefab,
        this.coolProgress.progress = this.taskProgress.progress = 0,
        this.btnManagerArr = [this.startBtn.node, this.receiveBtn.node, this.coolDownNode, this.taskProgNode],
        this.gifts[0].tag = this.firstTag,
        this.gifts[0].icon = this.coinIcon,
        this.gifts[0].value = this.coinCount,
        this.gifts[0].prefab = this.firstPrefab,
        this.gifts[1].tag = this.tag,
        this.gifts[1].icon = this.diamondIcon,
        this.gifts[1].value = this.diamondCount,
        this.gifts[1].prefab = this.secdPrefab,
        this._durationkey = u.BaseStorageKey.TaskBonus + t,
        this._coolDownkey = u.BaseStorageKey.CoolDown + t,
        this._statusKey = u.BaseStorageKey.ExploreTaskState + t,
        this._firstKey = "firstTask",
        f.StorageManager.setDailyTaskStorageKey(this._firstKey),
        this.grade != r.primary || m.BaseStorage.getInt(this._firstKey, 0) || (this.videoIcon.active = !1)
    },
    e.prototype.start = function() {
        this.strengthNum <= 0 ? this.strengthNode.active = !1 : this.strengthNode.getChildByName("Label").getComponent(cc.Label).string = "-" + this.strengthNum,
        this.status()
    },
    e.prototype.setState = function(t) {
        m.BaseStorage.setString(this._statusKey, t)
    },
    e.prototype.status = function() {
        switch (m.BaseStorage.getString(this._statusKey)) {
            case u.Status.start:
                this.setInform(1),
            this.showNode(this.startBtn.node);
            break;
            case u.Status.duration:
                this.setInform(0),
            this.showNode(this.taskProgNode),
            this.schedule(this.refreshDurationTime, .5),
            this.videoIcon.active && p.Util.videoExposure(u.VideoTab.dim12);
            break;
            case u.Status.receive:
                this.setInform(1),
            this.finish();
            break;
            case u.Status.cool:
                this.setInform(0),
            this.showNode(this.coolDownNode),
            this.schedule(this.refreshCoolDownTime, .5);
            break;
            default: this.setInform(1),
            this.showNode(this.startBtn.node);
        }
    },
    e.prototype.setInform = function() {},
    e.prototype.onEnable = function() {
        this.node.scale = 0,
        cc.tween(this.node).to(.5, {
            scale: 1
        },
        {
            easing: "elasticOut"
        }).start(),
        this.initGift()
    },
    e.prototype.showNode = function(t) {
        for (var e = 0; e < this.btnManagerArr.length; e++) {
            var o = this.btnManagerArr[e];
            o.active = t === o
        }
    },
    e.prototype.startClick = function() {
        if (h.default.getInstance().SendMessage(l.Broadcast_Func.Audio, l.Audio_ID.btn_click), this.strengthNum > 0) {
            if (! (s.default.vitData.num >= this.strengthNum)) return void d.default.show("体力不足");
            s.default.saveVitData(!1, this.strengthNum),
            cc.find("Canvas").getComponent(c.default).onSetOwnVit(!0)
        }
        this.videoIcon.active && p.Util.videoExposure(u.VideoTab.dim12),
        this.setState(u.Status.duration),
        this.refreshDurationStorageTime(),
        this.schedule(this.refreshDurationTime, .5),
        this.showNode(this.taskProgNode)
    },
    e.prototype.finishClick = function() {
        var t = this;
        h.default.getInstance().SendMessage(l.Broadcast_Func.Audio, l.Audio_ID.btn_click),
        this.videoIcon.active ? p.Util.showRewardVideo(function() {
            t.finish()
        }) : (this.videoIcon.active = !0, m.BaseStorage.setInt(this._firstKey, 1), this.finish())
    },
    e.prototype.finish = function() {
        this.setState(u.Status.receive),
        this.showNode(this.receiveBtn.node)
    },
    e.prototype.reciveClick = function() {
        h.default.getInstance().SendMessage(l.Broadcast_Func.Audio, l.Audio_ID.btn_click),
        this.refreshCoolDownStorageTime(),
        this.schedule(this.refreshCoolDownTime, .5),
        this.getGift(),
        this.coolDownTime > 0 ? (this.setState(u.Status.cool), this.showNode(this.coolDownNode)) : (this.setState(u.Status.start), this.showNode(this.startBtn.node))
    },
    e.prototype.getGift = function() {
        h.default.getInstance().SendMessage(l.Broadcast_Func.Audio, l.Audio_ID.get_gold);
        for (var t = [{
            tag: this.firstTag,
            icon: this.coinIcon,
            value: this.coinCount,
            prefab: this.firstPrefab
        },
        {
            tag: this.tag,
            icon: this.diamondIcon,
            value: this.diamondCount,
            prefab: this.secdPrefab
        }], e = 0; e < this.awards.length; e++) {
            var o = this.awards[e];
            _.default.receiveAward(o, t[e].prefab)
        }
        this.tag == u.BonusType.Diamond && this.addedBonus(t),
        this.firstTag == u.BonusType.Diamond && this.addedBonus([{
            tag: this.firstTag,
            icon: this.coinIcon,
            value: this.coinCount,
            prefab: this.firstPrefab
        }])
    },
    e.prototype.addedBonus = function(t) {
        var e = cc.instantiate(this.receiveAwardPrefab);
        e.getComponent(v.default).init(t, this.refresh.bind(this), !0, u.VideoTab.dim11),
        e.parent = cc.find("Canvas")
    },
    e.prototype.refresh = function() {},
    e.prototype.initGift = function() {
        this.awards = [];
        for (var t = 0; t < this.gifts.length; t++) {
            var e = this.gifts[t],
            o = cc.instantiate(this.awardPrefab);
            o.parent = this.giftCountainer,
            o.getComponent(g.default).Sprite.sizeMode = cc.Sprite.SizeMode.RAW,
            o.getComponent(g.default).Icon = e.icon,
            o.getComponent(g.default).Tag = e.tag,
            o.getComponent(g.default).Value = e.value,
            this.awards.push(o.getComponent(g.default))
        }
    },
    e.prototype.refreshCoolDownTime = function() {
        var t = this.getCoolDownTime();
        this.coolProgress.progress = 1 - t / y.default.convert_hours_to_milliseconds(this.coolDownTime),
        t <= 0 && (this.setState(u.Status.start), this.showNode(this.startBtn.node), this.unschedule(this.refreshCoolDownTime)),
        this.coolTimestamp.string = y.default.parse_timestamp_time_hours(t)
    },
    e.prototype.refreshDurationTime = function() {
        var t = this.getDurationTime();
        this.taskProgress.progress = 1 - t / y.default.convert_hours_to_milliseconds(this.taskTime),
        p.Util,
        t <= 0 && (this.finish(), this.unschedule(this.refreshDurationTime)),
        this.taskTimeLabel.string = y.default.parse_timestamp_time_hours(t)
    },
    e.prototype.getDurationTime = function() {
        return m.BaseStorage.getInt(this._durationkey, 0) - new Date().getTime()
    },
    e.prototype.getCoolDownTime = function() {
        return m.BaseStorage.getInt(this._coolDownkey, 0) - new Date().getTime()
    },
    e.prototype.refreshCoolDownStorageTime = function() {
        var t = new Date().getTime() + y.default.convert_hours_to_milliseconds(this.coolDownTime);
        m.BaseStorage.setInt(this._coolDownkey, t)
    },
    e.prototype.refreshDurationStorageTime = function() {
        var t = new Date().getTime() + y.default.convert_hours_to_milliseconds(this.taskTime);
        m.BaseStorage.setInt(this._durationkey, t)
    },
    a([w({
        type: cc.Enum(r)
    })], e.prototype, "grade", void 0),
    a([w(cc.Sprite)], e.prototype, "title", void 0),
    a([w(cc.Sprite)], e.prototype, "gradeFrame", void 0),
    a([w(cc.Label)], e.prototype, "timestamp", void 0),
    a([w(cc.Prefab)], e.prototype, "awardPrefab", void 0),
    a([w(cc.Prefab)], e.prototype, "receiveAwardPrefab", void 0),
    a([w(cc.Prefab)], e.prototype, "coinPrefab", void 0),
    a([w(cc.Prefab)], e.prototype, "boxPrefab", void 0),
    a([w(cc.SpriteFrame)], e.prototype, "coinIcon", void 0),
    a([w(cc.Node)], e.prototype, "giftCountainer", void 0),
    a([w(cc.Button)], e.prototype, "startBtn", void 0),
    a([w(cc.Node)], e.prototype, "strengthNode", void 0),
    a([w(cc.Node)], e.prototype, "coolDownNode", void 0),
    a([w(cc.Node)], e.prototype, "taskProgNode", void 0),
    a([w(cc.Button)], e.prototype, "receiveBtn", void 0),
    a([w(cc.Node)], e.prototype, "videoIcon", void 0),
    a([w(cc.Label)], e.prototype, "coolTimestamp", void 0),
    a([w(cc.Label)], e.prototype, "taskTimeLabel", void 0),
    a([w(cc.ProgressBar)], e.prototype, "coolProgress", void 0),
    a([w(cc.ProgressBar)], e.prototype, "taskProgress", void 0),
    a([w([cc.SpriteFrame])], e.prototype, "titleFrames", void 0),
    a([w([cc.SpriteFrame])], e.prototype, "giftFrames", void 0),
    a([w(cc.SpriteFrame)], e.prototype, "giftIcons", void 0),
    a([w(cc.SpriteFrame)], e.prototype, "firstGiftIcons", void 0),
    a([b], e)
} (cc.Component);
o.default = S